package com.yang.service.impl;

import com.aliyun.openservices.ons.api.SendResult;
import com.aliyun.openservices.shade.com.alibaba.fastjson.JSON;
import com.yang.config.AliRocketMQTopicProperties;
import com.yang.entity.FireMetaData;
import com.yang.entity.FireRecord;
import com.yang.entity.SatelliteRemoteSensingFireData;
import com.yang.service.AliRocketMQService;
import com.yang.utils.AliRocketMQUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Service
@Slf4j
public class AliRocketMQServiceImpl implements AliRocketMQService {

    @Autowired
    private AliRocketMQUtil aliRocketMQUtil;

    @Autowired
    private AliRocketMQTopicProperties rocketMQTopicProperties;

    /**
     * 发送山火消息测试
     * @param messageType 消息类型，该字段需要标记为tag
     */
    @Override
    public void sendFireData(String messageType) {
        SatelliteRemoteSensingFireData satelliteRemoteSensingFireData = new SatelliteRemoteSensingFireData();
        FireMetaData metaData = new FireMetaData();
        metaData.setMessageId(UUID.randomUUID().toString().replaceAll("-", ""));
        metaData.setMessageSource("空间技术公司");
//        metaData.setMessageType("normal");
        metaData.setMessageType(messageType);
        metaData.setDataType("fcst");
        satelliteRemoteSensingFireData.setMetaData(metaData);
        List<FireRecord> recordList = new ArrayList<>();
        FireRecord fireRecord = new FireRecord();
        fireRecord.setFileName("山火监测报告");
        fireRecord.setFileType(".pdf");
        recordList.add(fireRecord);
        satelliteRemoteSensingFireData.setRecords(recordList);
        log.info("开始推送山火数据...");
        SendResult sendResult = aliRocketMQUtil.sendMessage(rocketMQTopicProperties.getFireTest(), metaData.getMessageType(), JSON.toJSONString(satelliteRemoteSensingFireData));
        log.info("山火sendResult:{}", sendResult);
    }

}
